"""
Project Euler Problem 10: https://projecteuler.net/problem=10

Summation of primes

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.
"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = Thonny Python3.7.3
@creat_time = 2022/5/6
'''


from math import sqrt

def isPrime(n: int) -> bool:
    '''
    >>> not isPrime(1) and isPrime(2) and isPrime(3) and not isPrime(4) and isPrime(5) and  not isPrime(6) and  not isPrime(25)
    True
    '''
    if n<2:
        return False
    if n==2 or n==3:
        return True
    if n % 2 ==0:
        return False
    
    n_sqrt = int(sqrt(n))
    
    for i in range(3, n_sqrt + 1, 2):
        if n % i == 0:
            return False
    return True


def solution(upperBound: int = 1000000) -> int:
    '''
    >>> assert solution(1) == 0
    >>> assert solution(2) == 2
    >>> assert solution(5) == sum([2,3,5])
    >>> assert solution(6) == sum([2,3,5])
    >>> assert solution(10) == sum([2,3,5,7])
    '''
    
    if upperBound < 2:
        return 0
    if upperBound == 2:
        return 2
    
    res = 2
    i = 3
    while i <= upperBound:
        if isPrime(i):
            res += i
        i += 2

    return res

if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose = False)
    
    print(f"solution() = {solution()}")
    # solution() = 37550402023


    


